﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RCREEE.Library.Entities;
using System.Data;

namespace RCREEE.Web
{
    public partial class StrategicObjective_ViewAll : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //// Add the language code to session
                //Session.Add("LanguageCode", 1033);

                pnlstrategicObjectives_EE.Visible = false;
                pnlstrategicObjectives_RE.Visible = false;

                int countryId = 0;

                if (Request["C"] != null && Request["C"].ToString() != "")
                    countryId = Convert.ToInt32(Request["C"]);

                else if (Session["CountryId"] != null)
                    countryId = Convert.ToInt32(Session["CountryId"]);

                if (countryId != 0)
                {
                    ddlCountries.DataBind();
                    ddlCountries.SelectedValue = Convert.ToString(countryId);

                    pnlstrategicObjectives_EE.Visible = true;
                    pnlstrategicObjectives_RE.Visible = true;
                    PopulateGrids();
                }
            }
        }

        private void PopulateGrids()
        {
            if (ddlCountries.SelectedValue != "0" && ddlCountries.SelectedValue != null)
            {
                int _countryId = Convert.ToInt32(ddlCountries.SelectedValue);

                int _languageCode = 1033;
                if (Session["LanguageCode"] != null)
                    _languageCode = Convert.ToInt32(Session["LanguageCode"]);

                StrategicObjectives _strategicObjective = new StrategicObjectives();
                DataSet dsItems = _strategicObjective.GetAllStrategicObjectivesItemValues(_languageCode, _countryId);

                if (dsItems != null && dsItems.Tables[0].Rows.Count > 0)
                {
                    gvStrategicObjectives_EE.DataSource = dsItems.Tables[0];
                    gvStrategicObjectives_EE.DataBind();
                }
                else
                {
                    gvStrategicObjectives_EE.DataSource = null;
                    gvStrategicObjectives_EE.DataBind();
                }

                if (dsItems != null && dsItems.Tables[1].Rows.Count > 0)
                {
                    gvStrategicObjectives_RE.DataSource = dsItems.Tables[1];
                    gvStrategicObjectives_RE.DataBind();
                }
                else
                {
                    gvStrategicObjectives_RE.DataSource = null;
                    gvStrategicObjectives_RE.DataBind();
                }
            }
        }

        protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlCountries.SelectedValue == "0")
            {
                pnlstrategicObjectives_EE.Visible = false;
                pnlstrategicObjectives_RE.Visible = false;
            }
            else
            {
                pnlstrategicObjectives_EE.Visible = true;
                pnlstrategicObjectives_RE.Visible = true;
                PopulateGrids();
            }

        }

    }
}